﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <link type="text/css" rel="stylesheet" media="all" href="../styles/global.css"/>
    <link type="text/css" rel="stylesheet" media="all" href="../styles/global_color.css"/>
    <script language="javascript" type="text/javascript">
        function deleteRole() {
            var r = window.confirm("确定要删除此角色吗？");
            document.getElementById("operate_result_info").style.display = "block";
        }
    </script>
</head>
<body>
<!--Logo区域开始-->
<div id="header">
    <img src="../images/logo.png" alt="logo" class="left"/>
    <a href="/logout">[退出]</a>
</div>
<!--Logo区域结束-->
<!--导航区域开始-->
<div id="navi">
    <ul id="menu">
        <li><a href="/index" class="index_on"></a></li>
        <li id="lia1"><a href="/role_list" class="role_off"></a></li>
        <li id="lia2"><a href="/admin_list" class="admin_off"></a></li>
        <li id="lia3"><a href="/fee_list" class="fee_off"></a></li>
        <li id="lia4"><a href="/account_list" class="account_off"></a></li>
        <li id="lia5"><a href="/service_list" class="service_off"></a></li>
        <li id="lia6"><a href="/bill_list" class="bill_off"></a></li>
        <li id="lia7"><a href="/report_list" class="report_off"></a></li>
        <li><a href="/userInfo" class="information_off"></a></li>
        <li><a href="/userModifyPwd" class="password_off"></a></li>
    </ul>
</div>
<!--导航区域结束-->
<!--主要区域开始-->
<div id="main">
    <form action="" method="">
        <!--查询-->
        <div class="search_add">
            <input type="button" value="增加" class="btn_add" onclick="location.href='/role_add';"/>
        </div>
        <!--删除的操作提示-->
        <div id="operate_result_info" class="operate_success">
            <img src="../images/close.png" onclick="this.parentNode.style.display='none';"/>
            删除成功！
        </div> <!--删除错误！该角色被使用，不能删除。-->
        <!--数据区域：用表格展示数据-->
        <div id="data">
            <table id="datalist">
                <tr>
                <th>角色 ID</th>
                <th>角色名称</th>
                <th class="width600">拥有的权限</th>
                <th class="td_modi"></th>
                </tr>
            </table>
        </div>
        <!--分页-->
        <div id="pages">

        </div>
    </form>
</div>
<!--主要区域结束-->
<div id="footer">
    <p>[源自北美的技术，最优秀的师资，最真实的企业环境，最适用的实战项目]</p>
    <p>版权所有(C)云科技有限公司 </p>
</div>
</body>
<script src="/js/jquery-3.2.1.js"></script>
<script>
    var table = $("#datalist");
    rolepage();

    show();
    function show() {

        $.ajax({
            url: "/selectAllModules",
            type: "post",
            success: function (result) {

                if (result.indexOf("角色管理") == -1) {
                    document.getElementById("lia1").style.display = "none"
                }
                if (result.indexOf("管理员") == -1) {
                    document.getElementById("lia2").style.display = "none"
                }
                if (result.indexOf("资费管理") == -1) {
                    document.getElementById("lia3").style.display = "none"
                }
                if (result.indexOf("账务账号") == -1) {
                    document.getElementById("lia4").style.display = "none"
                }
                if (result.indexOf("业务账号") == -1) {
                    document.getElementById("lia5").style.display = "none"
                }
                if (result.indexOf("账单管理") == -1) {
                    document.getElementById("lia6").style.display = "none"
                }
                if (result.indexOf("报表") == -1) {
                    document.getElementById("lia7").style.display = "none"
                }


            }

        });
    }


    function rolepage() {
        $.ajax({
            url: "/rolepage",
            type: "post",
            data: {
                pageNum: 1,
                pageSize: 5
            },
            success: function (result) {
                resultData(result);
            }
        });
    }
    function page(pagenum) {
        $.ajax({
            url: "/rolepage",
            type: "post",
            data: {
                pageNum: pagenum,
                pageSize: 5
            },
            success: function (result) {
                resultData(result);
            }
        });
    }
    function tiao(roleid) {
        window.location.href = "/role_modi?roleid=" + roleid;
    }
    function setDelState(roleid) {
        $.ajax({
            url: "/delectRole",
            type: "post",
            data: {
                id:roleid
            },
            success:function (result) {
                window.location.href=result.msg;
            }
        });

    }
    function resultData(result) {
        $("#datalist").html("");
        $("#datalist").append("<tr>" +
                "<th>角色 ID</th>" +
                "<th>角色名称</th>" +
                "<th class='width600'>拥有的权限</th>" +
                "<th class='td_modi'></th>" +
                "</tr>");
        var pagenum = result.pageNum;
        //每页显示几条数据
        var pagesize = result.pageSize;
        var size = result.size;
        var startrow = result.startRow;
        var endrow = result.startRow;
        var total = result.total;
        var pages = result.pages;
        var firstpage = result.firstPage;
        var prepage = result.prePage;
        var nextpage = result.nextPage;
        var lastpage = result.lastPage;
        var isfirstpage = result.isFirstPage;
        var islastpage = result.isLastPage;
        var haspreviouspage = result.hasPreviiousPage;
        var hasnextpage = result.hasNextPage;
        var navigatepages = result.navigatePages;
        var navigatepagenums = result.navigatepageNums;
        var roleList = result.list;

        if (isfirstpage) {
            prepage = firstpage
        }
        if (islastpage) {
            nextpage = lastpage;
        }
        for (var i = 0; i < roleList.length; i++) {
            var role = roleList[i];
            var roleid = role.id;
            var rolename = role.roleName;
            var moduleList = role.moduleInfoList;
            var nameSum = "";
            for (var j = 0; j < moduleList.length; j++) {
                var module = moduleList[j];
                var modulename = module.name + ",";
                nameSum += modulename;
            }

            var tr = $("<tr></tr>");
            var tdid = $("<td></td>").text(roleid);
            var tdName = $("<td></td>").text(rolename);
            var tdRoleName = $("<td></td>").text(nameSum);
//            var a1 = $("<a href='/role_modi?roleid=" + roleid + "'>修改</a>");
//            var a2 = $("<a href='/delectRole?id=" + roleid + "' >删除</a>");
            var a1 = $("<input type='button' value='修改' class='btn_modify'  onclick='tiao(" + roleid + ")'/>");
            var a2= $("<input type='button' value='删除' class='btn_delete'  onclick='setDelState(" + roleid + ")'/>");
            var changeBtn = $("<td></td>");
            changeBtn.append(a1).append(a2);
            tr.append(tdid).append(tdName).append(tdRoleName).append(changeBtn);
            table.append(tr)
        }
        $("#pages").html("");
        var a11 = $("<a href='javascript:void(0)' onclick='page(" + firstpage + ")'></a>").text("首页");
        var a12 = $("<a href='javascript:void(0)' onclick='page(" + prepage + ")'></a>").text("上一页");
        $("#pages").append(a11).append(a12);
        for (var k = 1; k <= lastpage; k++) {
            $("#pages").append($("<a href='javascript:void(0)' onclick='page(" + k + ")' >" + k + "</a>"));
        }
        var a13 = $("<a href='javascript:void(0)' onclick='page(" + nextpage + ")'></a>").text("下一页");
        var a14 = $("<a href='javascript:void(0)' onclick='page(" + lastpage + ")'></a>").text("尾页");
        $("#pages").append(a13).append(a14);

    }


</script>
</html>
